package view;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JMenu;

import model.LessonGuide;
import eventHandling.Callback;
import eventHandling.EventBus;
import eventHandling.EventTyp;

/**
 * 
 * @author marcel
 *
 */
public class ImportDialogController implements Controller {

	private MainFrame mainFrame;
	private ImportDialog importDialog;
	private EventBus eventBus;
	private LessonGuide lessonGuide;

	public ImportDialogController(EventBus eventBus, MainFrame mainFrame,
			ImportDialog importDialog, LessonGuide lessonGuide) {
		this.eventBus = eventBus;
		this.mainFrame = mainFrame;
		this.importDialog = importDialog;
		this.lessonGuide = lessonGuide;

		JMenu menu = mainFrame.getJMenuBar().getMenu(0);

		//adds its menuItem to the main menu
		importDialog.insertMenuItem(menu);
		registerForEvents();
	}

	private void registerForEvents() {
		// import a lesson
		eventBus.register(EventTyp.Type.OPEN_IMPORT_DIALOG, new Callback() {
			
			public void actionPerformed() {
				JFileChooser fileChooser = new JFileChooser();
				int state = fileChooser.showOpenDialog(mainFrame);
				if (state == JFileChooser.APPROVE_OPTION) {
					File fileToImport = fileChooser.getSelectedFile();
					//TODO do import
					// if(fileToImport.getName().endsWith(PAUKER_EXTENSION));

					// lessonGuide.setCurrentLesson();
				}
			}
		});
	}

}
